﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Librarian.Shared;

namespace Librarian
{
    public partial class Init : Form
    {
        public Init()
        {
            InitializeComponent();
        }

        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);

            label1.Text = String.Format("El fichero actual contiene: {0} libros",
                BookRules.BookCount());
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                Import f = new Import();
                f.FormClosed += new FormClosedEventHandler(f_FormClosed);
                f.Show();
                this.Hide();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        void f_FormClosed(object sender, FormClosedEventArgs e)
        {
            Form f = sender as Form;
            if(f!=null)
                f.FormClosed -= new FormClosedEventHandler(f_FormClosed);
            this.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                Search f = new Search();
                f.FormClosed += new FormClosedEventHandler(f_FormClosed);
                f.Show();
                this.Hide();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string fileName=Path.Combine( Path.GetDirectoryName(this.GetType().Assembly.Location),
                "data.xml");
//            Program.Books.WriteXml(fileName);
            MessageBox.Show(this, "Datos guardados en:\n" + fileName, "info", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
